package com.onepiece.im.test

import com.onepiece.im.api.ChatGroupCommonService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.context.WebApplicationContext
import spock.lang.Specification

import java.time.LocalDate
import java.time.format.DateTimeFormatter

/**
 * Context test without explicit configuration annotation.
 */
class ApplicationSpecWithoutAnnotation extends Specification {

    @Autowired
    WebApplicationContext context

    @Autowired
    ChatGroupCommonService chatGroupService;

    def "should boot up without errors"() {
        expect: "web application context exists"
        context != null
        chatGroupService != null
    }

    def "month dateformat test"(){
        given:
        DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM")
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        def date = "2019-03"
        date = date + "-01"
        def lastDate = LocalDate.parse(date, dateFormatter).minusMonths(1).format(monthFormatter);
        expect:
        lastDate == "2019-02"
    }

}